﻿using IntelligentCoder;
using LPLS.Commons.DBModule;
using LPLS.DBEntities;
using LPLS.DBEntities.ConfigModels;
using LPLS.DBEntities.DbModels;
using LPLS.DBInterface.ConfigModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LPLS.DBServices.ConfigModels
{
    [AsyncMethodPoster(Deep = 10)]
    public partial class PropertyConfigService : DBBaseService, IPropertyConfigService
    {

      

        private readonly DBContext _dbContext;

        public PropertyConfigService(DBContext dbContext) : base(dbContext)
        {
        }

        /// <summary>
        /// 添加属性配置
        /// </summary>
        /// <param name="prop"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int Add(PropertyConfig prop)
        {
          return   _dbContext.GetDbContext(DataBaseName).Insertable(prop).ExecuteCommand();
        }   
        public int Delete(Guid id)
        {
          return   _dbContext.GetDbContext(DataBaseName).Deleteable<PropertyConfig>().Where(u => u.Id == id).ExecuteCommand();
        }
        public List<PropertyConfig> GetAll()
        {
            return _dbContext.GetDbContext(DataBaseName).Queryable<PropertyConfig>().ToList();
        }
        public PropertyConfig GetModelById(Guid id)
        {
            return _dbContext.GetDbContext(DataBaseName).Queryable<PropertyConfig>()
                .Where(e=>e.Id==id)?.First();
        }

        public override void InitDataBaseName()
        {
            DataBaseName = DatabaseEnum.SqliteConfig.ToString();
        }

        public int Update(PropertyConfig prop)
        {
          return   _dbContext.GetDbContext(DataBaseName).Updateable(prop).ExecuteCommand();
        }

    }
}
